/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package frame.TaiKhoan;

import dao.CuaHangDAO;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import myclass.MyInterFrame;
import pojo.Cuahang;
import pojo.Nhanvien;

/**
 *
 * @author Quan
 */
public class QLTaiKhoan extends MyInterFrame {

    private Nhanvien nv;
    private DefaultTableModel tablemodel;

    /**
     * Creates new form QLTaiKhoan
     */
    public QLTaiKhoan() {
        initComponents();
    }

    public QLTaiKhoan(Nhanvien nv) {
        initComponents();
        this.nv = nv;
        tablemodel = new DefaultTableModel();
        tablemodel.addColumn("ID");
        tablemodel.addColumn("Họ tên");
        tablemodel.addColumn("Email");
        tablemodel.addColumn("Số điện thoại");
        tablemodel.addColumn("Tên đăng nhập");
        tablemodel.addColumn("Ngày sinh");
        tablemodel.addColumn("Ngày tạo");
        tablemodel.addColumn("Người tạo");
        tablemodel.addColumn("Loại");
        tablemodel.addColumn("Của hàng");
        jt_nhanvien.setModel(tablemodel);
        LoadTaiKhoan();
        LoadCuaHang();
    }

    private void LoadTaiKhoan() {
        List<Nhanvien> ds = null;
        dao.NhanVienDAO nvdao = new dao.NhanVienDAO();
        try {
            ds = nvdao.LayDanhSach();
        } catch (Exception ex) {
            Logger.getLogger(QLTaiKhoan.class.getName()).log(Level.SEVERE, null, ex);
        }

        if (ds != null) {
            tablemodel.getDataVector().clear();
            for (int i = 0; i < ds.size(); i++) {
                Nhanvien nhanvien = ds.get(i);
                tablemodel.addRow(new Object[]{
                            nhanvien.getId(),
                            nhanvien.getHoten(),
                            nhanvien.getEmail(),
                            nhanvien.getSodienthoai(),
                            nhanvien.getTendangnhap(),
                            nhanvien.getNgaysinh(),
                            nhanvien.getNgaytaotaikhoan(),
                            nhanvien.getNhanvien(),
                            nhanvien.getLoaitk(),
                            nhanvien.getCuahang()
                        });
            }
        }
    }

    private void LoadCuaHang() {
        CuaHangDAO chdao = new CuaHangDAO();
        List<Cuahang> ds = null;
        try {
            ds = chdao.LayDanhSach();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(rootPane, ex.getMessage(), "Thông báo", JOptionPane.ERROR_MESSAGE);
            Logger.getLogger(QLTaiKhoan.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (ds != null) {
            for (int i = 0; i < ds.size(); i++) {
                Cuahang cuahang = ds.get(i);
                jcbb_cuahang.addItem(cuahang);
            }
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jt_nhanvien = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtf_id = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jtf_tendangnhap = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jtf_ngaytao = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jcbb_loaitaikhoan = new javax.swing.JComboBox();
        jcbb_cuahang = new javax.swing.JComboBox();
        jtf_nguoitao = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jtf_hoten = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jtf_ngaysinh = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jtf_sdt = new javax.swing.JTextField();
        jtf_email = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();

        setClosable(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        setIconifiable(true);
        setTitle("Tài khoản người dùng");

        jt_nhanvien.setAutoCreateRowSorter(true);
        jt_nhanvien.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jt_nhanvien.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jt_nhanvienMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jt_nhanvien);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Thông tin tài khoản"));

        jLabel1.setText("ID");

        jtf_id.setEditable(false);

        jLabel3.setText("Tên đăng nhập");

        jLabel6.setText("Ngày tạo");

        jtf_ngaytao.setEditable(false);

        jLabel7.setText("Người tạo");

        jLabel8.setText("Cửa hàng");

        jLabel9.setText("Loại tài khoản");

        jcbb_loaitaikhoan.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Quản lý", "Bán hàng", "Kho" }));

        jtf_nguoitao.setEditable(false);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel1)
                    .addComponent(jLabel6)
                    .addComponent(jLabel9)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtf_nguoitao)
                    .addComponent(jtf_tendangnhap)
                    .addComponent(jtf_id)
                    .addComponent(jtf_ngaytao)
                    .addComponent(jcbb_loaitaikhoan, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jcbb_cuahang, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jtf_id, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jtf_tendangnhap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtf_ngaytao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jtf_nguoitao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jcbb_cuahang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jcbb_loaitaikhoan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Thông tin cá nhân"));

        jLabel2.setText("Họ tên");

        jLabel4.setText("Ngày sinh");

        jLabel10.setText("Điện thoại");

        jLabel5.setText("Email");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel4)
                    .addComponent(jLabel10)
                    .addComponent(jLabel5))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtf_email)
                    .addComponent(jtf_ngaysinh)
                    .addComponent(jtf_hoten)
                    .addComponent(jtf_sdt))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jtf_hoten, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jtf_ngaysinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jtf_sdt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtf_email, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButton1.setText("Đóng");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Xóa");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Sửa");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Thêm mới");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText("Đặt lại mật khẩu");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 868, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButton5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 237, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2)
                    .addComponent(jButton3)
                    .addComponent(jButton4)
                    .addComponent(jButton5))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);

    }//GEN-LAST:event_jButton1ActionPerformed

    private void jt_nhanvienMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jt_nhanvienMouseClicked
        // TODO add your handling code here:
        int index = jt_nhanvien.getSelectedRow();
        if (index != -1) {
            jtf_id.setText(tablemodel.getValueAt(index, 0).toString());
            jtf_hoten.setText(tablemodel.getValueAt(index, 1).toString());
            jtf_email.setText(tablemodel.getValueAt(index, 2).toString());
            jtf_sdt.setText(tablemodel.getValueAt(index, 3).toString());
            jtf_tendangnhap.setText(tablemodel.getValueAt(index, 4).toString());
            DateFormat df = new SimpleDateFormat("dd/MM/yyyy");

            if (tablemodel.getValueAt(index, 5) != null && tablemodel.getValueAt(index, 5).getClass() == Timestamp.class) {
                jtf_ngaysinh.setText(df.format((Date) tablemodel.getValueAt(index, 5)));
            } else {
                jtf_ngaysinh.setText(null);
            }

            if (tablemodel.getValueAt(index, 7) != null && tablemodel.getValueAt(index, 7).getClass() == Nhanvien.class) {
                jtf_nguoitao.setText(((Nhanvien) tablemodel.getValueAt(index, 7)).getHoten());
            } else {
                jtf_nguoitao.setText(null);
            }

            jtf_ngaytao.setText(tablemodel.getValueAt(index, 6).toString());
            for (int i = 0; i < jcbb_cuahang.getItemCount(); i++) {
                if (((Cuahang) jcbb_cuahang.getItemAt(i)).getId() == ((Cuahang) tablemodel.getValueAt(index, 9)).getId()) {
                    jcbb_cuahang.setSelectedIndex(i);
                }
            }
            String loaitk = (String) tablemodel.getValueAt(index, 8);
            for (int i = 0; i < jcbb_loaitaikhoan.getItemCount(); i++) {
                String loaitk2 = (String) jcbb_loaitaikhoan.getItemAt(i);
                if (loaitk.equals(loaitk2)) {
                    jcbb_loaitaikhoan.setSelectedIndex(i);
                }
            }
        }
    }//GEN-LAST:event_jt_nhanvienMouseClicked

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        Nhanvien nhanvien = new Nhanvien();
        nhanvien.setCuahang((Cuahang) jcbb_cuahang.getSelectedItem());
        nhanvien.setEmail(jtf_email.getText());
        nhanvien.setHoten(jtf_hoten.getText());
        nhanvien.setLoaitk((String) jcbb_loaitaikhoan.getSelectedItem());
        DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
        try {
            nhanvien.setNgaysinh(df.parse(jtf_ngaysinh.getText()));
        } catch (ParseException ex) {
            Logger.getLogger(QLTaiKhoan.class.getName()).log(Level.SEVERE, null, ex);
        }
        nhanvien.setNgaytaotaikhoan(new Date());
        nhanvien.setSodienthoai(jtf_sdt.getText());
        nhanvien.setTendangnhap(jtf_tendangnhap.getText());
        nhanvien.setNhanvien(this.nv);
        nhanvien.setMatkhau(nhanvien.getTendangnhap());

        dao.NhanVienDAO nvdao = new dao.NhanVienDAO();
        try {
            nvdao.Them(nhanvien);
            LoadTaiKhoan();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(rootPane, e.getMessage(), "Thông báo", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        dao.NhanVienDAO nvdao = new dao.NhanVienDAO();
        Nhanvien nhanvien = null;

        long id_nv = Long.valueOf(jtf_id.getText());
        try {
            nhanvien = (Nhanvien) nvdao.Lay(id_nv);
        } catch (Exception ex) {
            Logger.getLogger(QLTaiKhoan.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (nhanvien != null) {
            nhanvien.setCuahang((Cuahang) jcbb_cuahang.getSelectedItem());
            nhanvien.setEmail(jtf_email.getText());
            nhanvien.setHoten(jtf_hoten.getText());
            nhanvien.setLoaitk((String) jcbb_loaitaikhoan.getSelectedItem());
            DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
            try {
                nhanvien.setNgaysinh(df.parse(jtf_ngaysinh.getText()));
            } catch (ParseException ex) {
                Logger.getLogger(QLTaiKhoan.class.getName()).log(Level.SEVERE, null, ex);
            }
            nhanvien.setSodienthoai(jtf_sdt.getText());
            nhanvien.setTendangnhap(jtf_tendangnhap.getText());
            try {
                nvdao.Sua(nhanvien);
                LoadTaiKhoan();
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(rootPane, ex.getMessage(), "Thông báo", JOptionPane.ERROR_MESSAGE);
                Logger.getLogger(QLTaiKhoan.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        dao.NhanVienDAO nvdao = new dao.NhanVienDAO();
        Nhanvien nhanvien = null;

        long id_nv = Long.valueOf(jtf_id.getText());
        try {
            nhanvien = (Nhanvien) nvdao.Lay(id_nv);
        } catch (Exception ex) {
            Logger.getLogger(QLTaiKhoan.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (nhanvien != null) {
            try {
                nvdao.Xoa(nhanvien);
                LoadTaiKhoan();
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(rootPane, ex.getMessage(), "Thông báo", JOptionPane.ERROR_MESSAGE);
                Logger.getLogger(QLTaiKhoan.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(QLTaiKhoan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new QLTaiKhoan().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JComboBox jcbb_cuahang;
    private javax.swing.JComboBox jcbb_loaitaikhoan;
    private javax.swing.JTable jt_nhanvien;
    private javax.swing.JTextField jtf_email;
    private javax.swing.JTextField jtf_hoten;
    private javax.swing.JTextField jtf_id;
    private javax.swing.JTextField jtf_ngaysinh;
    private javax.swing.JTextField jtf_ngaytao;
    private javax.swing.JTextField jtf_nguoitao;
    private javax.swing.JTextField jtf_sdt;
    private javax.swing.JTextField jtf_tendangnhap;
    // End of variables declaration//GEN-END:variables
}
